﻿using Mrc.Common;
using System;
using System.Collections.Generic;
using System.Text;

namespace Mrc.Application
{
    /// <summary>
    /// 重复提交验证
    /// </summary>
    public class ResubmitVerifyExtension
    {
        /// <summary>
        /// 键值是否存在 不存在则新建
        /// </summary>
        /// <param name="key"></param>
        /// <param name="sec"></param>
        /// <returns></returns>
        public static bool IsResubmit(string key, int sec)
        {
            if (RedisHelper.Exists(key)) return true;
            RedisHelper.Set(key,"", sec);
            return false;
        }
     
        /// <summary>
        /// 提交频繁验证
        /// </summary>
        /// <param name="key"></param>
        /// <param name="sec"></param>
        public static void Verify(string key, int sec = 3)
        {
            if (IsResubmit(key, sec)) throw new MrcException("提交频繁,请稍后再试");
        }

    }

}
